<?php

class Webmix_Model_DbTable_Countries extends Engine_Db_Table {
	protected $_rowClass = 'Webmix_Model_Country';
    
    public function getCountryByUser($user_id ){
        $webmixTable = Engine_Api::_()->getDbtable('webmixes','webmix');
        $wname = $webmixTable->info('name');
        $userCountry =$webmixTable->userCountry($user_id);
     
        $select = $this->select();
        $select->from(array('country'=>$this->info('name')),array('*'));
        if(!empty($userCountry)){
            $select->where('country.country_id not in(?)',$userCountry);
            
            
        }
        $select->join($wname,"$wname.country_id = country.country_id ",null)
                ->where("$wname.type = 'system' ")
                ->where("public = 1");
        $select->where('selected = 1');
        
        $rows = $this->fetchAll($select);
        return $rows;
    }

    public function getCountryByTitle($title ){
  
        $select = $this->select()
                        ->where('title = ?',$title)
                        ->limit(1);
        $rows = $this->fetchAll($select);
        return $rows;
    }    
 }